import json
import time
from kafka import KafkaProducer



log_file_1 = r'/data/hsy/data/2000/轨迹_车辆轨迹_最后1小时_合并处理后_雷达感知数据_最终数据合并.log'
# 记录上一条消息的时间戳和处理结束时间
f_write = open('./test.log','a',encoding='utf-8')
with open(log_file_1, 'r') as file:
    while True:
        line = file.readline().strip()
        if line:
            data = json.loads(line)
            ts = data['ts']
            objs = data['objs']
            # 记录处理开始时间
            process_start = time.time()
            objs_temp = []
            for obj in objs:
                if obj['sn'] in ['S_20','S_21','S_22']:
                    objs_temp.append(obj)
            # 构建消息
            message = {
                'ts': int(process_start * 1000),  # 使用处理开始时间作为消息时间戳
                'obj': objs_temp
            }
            f_write.write(str(message).replace("'",'"') + "\n")
        else:
            break

